package com.bai.easyui.utils;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created by Admin on 2/9 0009.
 */
public class JDBCUtil {
    public static Connection getConnection() {
        Connection connection=null;
        try {
            Properties info=new Properties();
            InputStream in=
                    JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
            info.load(in);
            String driverClass=info.getProperty("driverClass");
            String url=info.getProperty("url");
            String username=info.getProperty("user");
            String password=info.getProperty("password");
            info.put("username",username);
            info.put("password",password);
            Class.forName(driverClass);
             connection=DriverManager.getConnection(url,info);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }

    public static void release(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
